package com.example.ytyproject.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.ytyproject.component.MinioComponent;
import com.example.ytyproject.entity.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file/minio")
public class FileController {

    @Autowired
    private MinioComponent minioComponent;

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R uploadByMinio(@RequestParam(name = "file") MultipartFile file) {
        //返回存储路径
        String path = minioComponent.uploadFile(file, "admin/test/");
        return R.ok(path);
    }
}
